{include file="common/head"}

<head>
  <title>客户资料编辑</title>
  <link rel="stylesheet" href="/static/flatpickr/flatpickr.min.css">
  <script src="/static/flatpickr/flatpickr.js"></script>

</head>
<style>
  label {
    width: 18%;
  }

  .form-control {
    display: inline-block;
    width: 80%;
  }

  h2 {
    height: 50px;
    line-height: 30px;
  }

  .box {
    border: 1px solid #ccc;
    padding: 20px;
    box-shadow: 1px 1px 4px #888;
    position: relative;
  }
</style>

<body>
  <div class="container p-3" style="margin-left: 10px;">

    <form method="post" action="/index.php/customer/edit" enctype="multipart/form-data">
      <input type="hidden" name="id" id="id" value="{$data.id}" />
      <div class="row">
        <div class="col box" style="margin-right:10px;">
          <h2>客户编号：{$data.id} </h2>
          <div class="mb-3 mt-3">
            <!-- <lable for="name" class="form-label">编号:</label> -->
            <input type="hidden" class="form-control" value="{$data.id}" placeholder="" disabled />
          </div>
          <div class="mb-3">
            <label for="title" class="form-label">顾客名称:</label>
            <input type="text" class="form-control" id="name" name="name" value="{$data.name}" placeholder="name" />
          </div>
          <div class="mb-3">
            <label for="name2" class="form-label">顾客名称2:</label>
            <input type="text" class="form-control" id="name2" name="name2" value="{$data.name2}"
              placeholder="english name" />
          </div>
          <div class="mb-3">
            <label for="contact" class="form-label">联系人:</label>
            <input type="text" class="form-control" id="id_card" name="id_card" value="{$data.id_card}"
              placeholder="customer contact name" />
          </div>
          <div class="mb-3">
            <label for="mobile" class="form-label">联系人手机:</label>
            <input type="text" class="form-control" id="mobile" name="mobile" value="{$data.mobile}"
              placeholder="mobile" />
          </div>

          <div class="mb-3">
            <label for="address" class="form-label">地址:</label>
            <input type="text" class="form-control" id="address" name="address" value="{$data.address}"
              placeholder="客户地址 Adderss" />
          </div>
          <div class="mb-3">
            <label for="sales" class="form-label">业务员:</label>
            <select name="sales" class="form-control">
              {foreach $sales_list as $v}
              {if $v['id']==$data['sales']}
              <option value="{$v['id']}" selected>{$v['name']}</option>
              {else}
              <option value="{$v['id']}">{$v['name']}</option>
              {/if}
              {/foreach}
            </select>

          </div>

          <div
            style="margin-top: 10px;position: absolute;bottom: 0px;right:10px;padding: 10px ;min-width: 95%;text-align: right;">
            <!--         <button  type="button" class="btn btn-info" onclick="doSave()">上一个</button>
        <button  type="button" class="btn btn-secondary" onclick="doSave()">下一个</button> -->
          </div>

        </div>


        <div class="col box">
          <h2>其他信息：{$data.fee_id_name}</h2>
          <div class="mb-3" style="width:70%;">
            <label for="type" class="form-label">顾客类别:</label>
            <select id="type" name="type" class="form-control">
              {foreach $type as $k=>$v}
              <option value="{$k}" {if $data['type']==$k} selected {/if}>{$v}</option>
              {/foreach}
            </select>

          </div>

          <div class="mb-3" style="width:70%;">
            <label for="" class="form-label">是否有用:</label>
            <input type="radio" class="form-check-input" id="radio1" name="status" value="1" {if $data.status==1}
              checked {/if} />
            <label class="form-check-label" for="radio1">启用</label>
            <input type="radio" class="form-check-input" id="radio2" name="status" value="2" {if $data.status==2}
              checked {/if} />
            <label class="form-check-label" for="radio2">不用了</label>
          </div>

          <div class="mb-3" style="width:70%;">
            <label for="" class="form-label">跟进内容:</label>
            <textarea id="follow_memo" name="follow_memo" class="form-control" style="height:120px;"
              placeholder="随手记"></textarea>
          </div>

          <div
            style="position: absolute;top:20px;right:20px;width:140px; padding: 5px; border:1px solid #ccc;text-align: center;">
            <img src="{$data.image}" style="width: 130px;" /><br />
            <input type="file" name="file" /> <br>
          </div>

          <div class="text-left"
            style="margin-top: 10px;border-top:1px solid #d7d7d7;position: absolute;bottom: 0px;left:10px;padding: 10px ;min-width: 95%;">
            {if $user.group_id==1}
            <button type="button" class="btn btn-primary" onclick="doSave()">保存修改</button>
            {/if}
          </div>
        </div>
      </div>
    </form>

    <div style="height: 10px;"></div>

    <div id="log_box">

      <div class="btn-group" role="group" aria-label="Basic radio toggle button group">
        <input type="radio" class="btn-check" name="btnradio" id="btnradio1" autocomplete="off" checked>
        <label class="btn btn-outline-info" for="btnradio1">跟进记录</label>

        <input type="radio" class="btn-check" name="btnradio" id="btnradio2" autocomplete="off">
        <label class="btn btn-outline-info" for="btnradio2">修改记录</label>

        <input type="radio" class="btn-check" name="btnradio" id="btnradio3" autocomplete="off">
        <label class="btn btn-outline-info" for="btnradio3">订单记录</label>

        <input type="radio" class="btn-check" name="btnradio" id="btnradio4" autocomplete="off">
        <label class="btn btn-outline-info" for="btnradio4">账单记录</label>
      </div>

      <div>
        <table id="follow_log" class="table table-sm table-hover table-striped">
          <thead>
            <tr>
              <th>序号</th>
              <!-- <th>学员</th> -->
              <th>跟进内容</th>
              <th>操作人</th>
              <th>日期</th>
            </tr>
          </thead>
          <tbody>

          </tbody>
        </table>

        <table id="allocate_log" class="table table-sm table-hover table-striped" style="display: none;">
          <thead>
            <tr>
              <th>序号</th>
              <th>备注</th>
              <th>操作人</th>
              <th>日期</th>
            </tr>
          </thead>
          <tbody>

          </tbody>
        </table>

        <table id="order_log" class="table table-sm table-hover table-striped" style="display: none;">
          <thead>
            <tr>
              <th>序号</th>
              <th>订单号</th>
              <th>订单内容</th>
              <th>订单备注</th>
              <th>订单状态</th>
              <th>日期</th>
            </tr>
          </thead>
          <tbody>

          </tbody>
        </table>

        <table id="acc_log" class="table table-sm table-hover table-striped" style="display: none;">
          <thead>
            <tr>
              <th>序号</th>
              <th>类别</th>
              <th>金额</th>
              <th>备注</th>
              <th>状态</th>
              <th>日期</th>
            </tr>
          </thead>
          <tbody>

          </tbody>
        </table>

      </div>

    </div>


  </div>

  <script type="text/javascript">
    flatpickr("#birth_date", {});
    $(".birth_date").flatpickr({
      enableTime: true,
      dateFormat: "Y-m-d H:i:s",
    });

    $(function () {

      $("#btnradio1").on('click', function () {
        $('table').hide();
        $.post('/log/log', { table: 'follow_log', customer_id: $("#id").val() }, function (res) {
          //console.log(res);
          $("#follow_log tbody").empty();
          for (var i = 0; i < res.length; i++) {
            var tr = "<tr>";
            tr += "<td>" + (i + 1) + "</td>";
            //tr+="<td>"+res[i].customer_id_name+"</td>";
            tr += "<td>" + res[i].memo + "</td>";
            tr += "<td>" + res[i].user_id_name + "</td>";
            tr += "<td>" + res[i].create_time + "</td>";
            tr += "</tr>";

            //console.log(tr);
            $("#follow_log tbody").append(tr);

          }

          $("#follow_log").show();
        });
      })

      $("#btnradio1").trigger('click');

      $("#btnradio2").on('click', function () {
        $('table').hide();
        $.post('/log/log', { table: 'allocate_log', customer_id: $("#id").val() }, function (res) {
          //console.log(res);
          $("#allocate_log tbody").empty();
          for (var i = 0; i < res.length; i++) {
            var tr = "<tr>";
            tr += "<td>" + (i + 1) + "</td>";
            tr += "<td>" + res[i].memo + "</td>";
            tr += "<td>" + res[i].user_id_name + "</td>";
            tr += "<td>" + res[i].create_time + "</td>";
            tr += "</tr>";

            //console.log(tr);
            $("#allocate_log tbody").append(tr);
            $("#allocate_log").show();
          }

        });

      })
      $("#btnradio3").on('click', function () {
        var cid = $("#id").val();
        $('table').hide();

        $.post('/log/order_list', { customer_id: cid, log: 1 }, function (res) {
          //console.log(res);

          $("#order_log tbody").empty();
          for (var i = 0; i < res.length; i++) {
            var tr = "<tr>";
            tr += "<td>" + (i + 1) + "</td>";
            tr += "<td>" + res[i].order_no + "</td>";
            tr += "<td>" + res[i].goods_list + "</td>";
            tr += "<td>" + res[i].memo + "</td>";
            tr += "<td>" + res[i].status_name + "</td>";
            tr += "<td>" + res[i].create_time + "</td>";
            tr += "</tr>";

            //console.log(tr);
            $("#order_log tbody").append(tr);
            $("#order_log").show();
          }


        });
      })


      $("#btnradio4").on('click', function () {
        $('table').hide();
        var cid = $("#id").val();
        $.post('/log/acc_log', { customer_id: cid }, function (res) {
          console.log(res);

          $("#acc_log tbody").empty();
          for (var i = 0; i < res.length; i++) {
            var tr = "<tr>";
            tr += "<td>" + (i + 1) + "</td>";
            tr += "<td>" + res[i].type_name + "</td>";
            tr += "<td>" + res[i].money + "</td>";
            tr += "<td>" + res[i].memo + "</td>";
            tr += "<td>" + res[i].status_name + "</td>";
            tr += "<td>" + res[i].create_time + "</td>";
            tr += "</tr>";

            //console.log(tr);
            $("#acc_log tbody").append(tr);
            $("#acc_log").show();
          }

        });
      })


      $("#find_inviter").on('click', function () {
        if (!$("#inviter_name").val()) {
          $("#inviter").val('');
          layer.msg('请输入姓名或者手机设置邀请人,清空内容可以删除邀请人！'); return;
        }
        $.post('/index.php/customer/getOne', { nameOrMobile: $("#inviter_name").val() }, function (res) {
          if (res.code) {
            var data = res.data;
            console.log(data.id + "," + $("#id").val());
            if (data.id == $("#id").val()) {
              $("#inviter").val('');
              layer.msg("太离谱了吧，自己邀请自己!");
            } else if (data.inviter == $("#id").val()) {
              $("#inviter").val('');
              layer.msg("太离谱了吧，互相邀请对方是不对的哦!");
            } else {
              var inviter = data.id;
              $("#inviter").val(inviter);
              layer.msg(res.msg);
            }
          } else {
            layer.msg(res.msg);
          }

        })
      })

    })

    function doSave() {
      if (!$("#name").val()) {
        layer.msg("无效的名称(Invalid name)!");
        return 0;
      }
      if (!$("#mobile").val()) {
        layer.msg("无效的电话(Invalid mobile)!");
        return 0;
      }


      //询问框
      layer.confirm('是否确定保存?', {
        btn: ['是的', '取消'] //按钮
      }, function () {
        $('form').submit();
      }, function () {
        layer.msg("Cancel!");
        return 0;
      });
    }

  </script>


</body>

</html>